//
//  ByViewRedPacketComeInfomation.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/11/13.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByViewRedPacketComeInfomation.h"

@implementation ByViewRedPacketComeInfomation
{
    UIImageView *_bgView;               // 背景
    UIImageView *_iconView;             // 商标
    UILabel     *_nameLabel;            // 商家名称
    UILabel     *_moneyLabel;           // 金额
    UILabel     *_distanceLabel;        // 距离
    UILabel     *_conditionLabel;       // 条件
    UIButton    *_getButton;            // 查看地址
    
    UIButton    *_cancelButton;         // 取消按钮
}
- (instancetype)init {
    
    if (self = [super init]) {
        
        self.damping = 0.6;
        self.positionMode = ZKBombPopModeCenter;
        self.popMode = ZKBombPopModeCenter;
        [self disableTapMask];
        [self createContentView];
    }
    return self;
}

- (void)createContentView {
    
    
    UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH * 0.8, 450)];
    self.contentView = contentView;
    
    
    
    // 背景
    _bgView = [UIImageView new];
    _bgView.image = [UIImage imageWithColor:[UIColor redColor]];
    [self.contentView addSubview:_bgView];
    
    // 商标
    _iconView = [UIImageView new];
    _iconView.image = [UIImage imageWithColor:[UIColor cyanColor]];
    [self.contentView addSubview:_iconView];
    
    // 商家名称
    _nameLabel = [[UILabel alloc] init];
    _nameLabel.numberOfLines = 2;
    _nameLabel.text = @"大森林保险";
    _nameLabel.font = FONT(18);
    _nameLabel.textAlignment = NSTextAlignmentCenter;
    _nameLabel.textColor = [UIColor whiteColor];
    [self.contentView addSubview:_nameLabel];
    
    // 金额
    _moneyLabel = [[UILabel alloc] init];
    _moneyLabel.font = FONT(40);
    _moneyLabel.adjustsFontSizeToFitWidth = true;
    _moneyLabel.textAlignment = NSTextAlignmentCenter;
    _moneyLabel.backgroundColor = [UIColor yellowColor];
    _moneyLabel.textColor = BY_GOLD_COLOR;
    [self.contentView addSubview:_moneyLabel];
    _moneyLabel.layer.cornerRadius = 70;
    _moneyLabel.layer.masksToBounds = true;
    
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:@"￥999"];
    [attr addAttribute:NSFontAttributeName value:FONT(20) range:NSMakeRange(0, 1)];
    _moneyLabel.attributedText = attr;
    
    
    // 距离
    _distanceLabel = [[UILabel alloc] init];
    _distanceLabel.adjustsFontSizeToFitWidth = true;
    _distanceLabel.text = @"该店距离您约300m，快去体验吧！";
    _distanceLabel.font = FONT(18);
    _distanceLabel.textAlignment = NSTextAlignmentCenter;
    _distanceLabel.textColor = BY_GOLD_COLOR;
    [self.contentView addSubview:_distanceLabel];
    
    // 使用条件
    _conditionLabel = [[UILabel alloc] init];
    _conditionLabel.text = @"使用条件：消费满8888可用";
    _conditionLabel.font = FONT(15);
    _conditionLabel.textAlignment = NSTextAlignmentCenter;
    _conditionLabel.textColor = [UIColor whiteColor];
    [self.contentView addSubview:_conditionLabel];
    
    // 查看地址按钮
    _getButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _getButton.backgroundColor = BY_THEME_COLOR;
    _getButton.titleLabel.font = FONT(20);
    _getButton.layer.cornerRadius = 4;
    _getButton.layer.masksToBounds = true;
    [_getButton setTitle:@"领取" forState:UIControlStateNormal];
    [_getButton setTitleColor:BY_GOLD_COLOR forState:UIControlStateNormal];
    [_getButton addTarget:self action:@selector(lookAddress) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_getButton];
    
    // 取消按钮
    _cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_cancelButton setImage:[UIImage imageNamed:@"取消"] forState:UIControlStateNormal];
    [_cancelButton addTarget:self action:@selector(cancel) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_cancelButton];
    
    
    // 布局
    [_bgView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).insets(UIEdgeInsetsMake(0, 0, 60, 0));
    }];
    [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(60, 60));
        make.centerX.equalTo(@0);
        make.top.equalTo(@20);
    }];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_iconView.mas_bottom);
        make.left.equalTo(@10);
        make.right.equalTo(@(-10));
        make.height.equalTo(@40);
    }];
    [_moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(140, 140));
        make.centerX.equalTo(@0);
        make.top.equalTo(_nameLabel.mas_bottom);
    }];
    [_distanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_moneyLabel.mas_bottom).offset(10);
        make.left.equalTo(@10);
        make.right.equalTo(@(-10));
        make.height.equalTo(@20);
    }];
    [_conditionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.equalTo(_distanceLabel);
        make.top.equalTo(_distanceLabel.mas_bottom).offset(5);
    }];
    [_getButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@40);
        make.top.equalTo(_conditionLabel.mas_bottom).offset(10);
        make.width.equalTo(self.contentView).multipliedBy(0.7);
        make.centerX.equalTo(@0);
    }];
    [_cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(@0);
        make.size.mas_equalTo(CGSizeMake(40, 40));
        make.top.equalTo(_bgView.mas_bottom).offset(10);
    }];
}




#pragma mark - 点击事件
- (void)lookAddress {
    
}
- (void)cancel {
    [self remove];
}

@end
